package com.daxt;


import com.daxt.model.service.base.vo.UserDept;
import org.activiti.spring.boot.SecurityAutoConfiguration;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.ImportResource;
import org.springframework.scheduling.TaskScheduler;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;

//@ServletComponentScan
@EnableScheduling
@ImportResource("classpath:ureport-console-context.xml")
@SpringBootApplication(exclude={SecurityAutoConfiguration.class})
//@SpringBootApplication//(exclude={DataSourceAutoConfiguration.class})
public class DaxtApplication {

	public static void main(String[] args) {
		SpringApplication.run(DaxtApplication.class, args);
		System.out.println("项目启动");
	}

	 @Bean
	  public CorsFilter corsFilter() {
	    final UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
	    final CorsConfiguration config = new CorsConfiguration();
	    config.setAllowCredentials(true);
	    config.addAllowedOrigin("*");
	    config.addAllowedHeader("*");
	    config.setMaxAge(18000L);
	    config.addAllowedMethod("OPTIONS");
	    config.addAllowedMethod("HEAD");
	    config.addAllowedMethod("GET");
	    config.addAllowedMethod("PUT");
	    config.addAllowedMethod("POST");
	    config.addAllowedMethod("DELETE");
	    config.addAllowedMethod("PATCH");
	    source.registerCorsConfiguration("/**", config);
	    return new CorsFilter(source);
	  }

/*	 @Bean
	 public ServletRegistrationBean<UReportServlet> ureportServlet() {
		 ServletRegistrationBean<UReportServlet> bean=new ServletRegistrationBean<>(new UReportServlet());
		 bean.addUrlMappings("/ureport/*");
		 return bean;
	 }*/
	 @Bean
	 public TaskScheduler  taskScheduler() {
		 ThreadPoolTaskScheduler taskScheduler=new ThreadPoolTaskScheduler();
		 taskScheduler.setPoolSize(10);
		 taskScheduler.initialize();
		 return taskScheduler;
	 }



}
